package com.cyan.app.workflow.util;

import android.graphics.Bitmap;
import android.widget.ImageView;

import com.cyan.app.workflow.R;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;

/**
 * Created by Administrator on 2015/5/6.
 */
public class LoadingImgUtil {

    private static DisplayImageOptions LIVESCORE_PIC_OPTIONS = new DisplayImageOptions.Builder()
            .showImageOnLoading(R.drawable.loading)
            .showImageForEmptyUri(R.drawable.loading)
            .showImageOnFail(R.drawable.loading)
            .resetViewBeforeLoading(true)
            .delayBeforeLoading(10)
            .cacheInMemory(true)
            .cacheOnDisc(true)
            .considerExifParams(true)
            .imageScaleType(ImageScaleType.IN_SAMPLE_INT)
            .bitmapConfig(Bitmap.Config.RGB_565)
//            .displayer(new FadeInBitmapDisplayer(500))
            .build();


    private static DisplayImageOptions ROUNDED_PIC_OPTIONS = new DisplayImageOptions.Builder()
            .showImageOnLoading(R.drawable.loading)
            .showImageForEmptyUri(R.drawable.loading)
            .showImageOnFail(R.drawable.loading)
            .resetViewBeforeLoading(true)
            .delayBeforeLoading(10)
            .cacheInMemory(true)
            .cacheOnDisc(true)
            .considerExifParams(true)
            .imageScaleType(ImageScaleType.EXACTLY_STRETCHED)
            .bitmapConfig(Bitmap.Config.RGB_565)
            .displayer(new RoundedBitmapDisplayer(2000))
            .build();


    private static DisplayImageOptions BANNER_PIC_OPTIONS = new DisplayImageOptions.Builder()
            .showImageOnLoading(R.drawable.loading)
            .showImageForEmptyUri(R.drawable.loading)
            .showImageOnFail(R.drawable.loading)
            .resetViewBeforeLoading(true)
            .delayBeforeLoading(10)
            .cacheInMemory(true)
            .cacheOnDisc(true)
            .considerExifParams(true)
            .imageScaleType(ImageScaleType.IN_SAMPLE_INT)
            .bitmapConfig(Bitmap.Config.RGB_565)
            .displayer(new FadeInBitmapDisplayer(1500))
            .build();

    public static void loadLiveScoreImg(String url, ImageView imgview) {
        ImageLoader imageLoader = ImageLoader.getInstance();
        imageLoader.displayImage(url, imgview, LIVESCORE_PIC_OPTIONS);
    }

    public static void loadRounedImg(String url, ImageView imgview) {
        ImageLoader imageLoader = ImageLoader.getInstance();
        imageLoader.displayImage(url, imgview, ROUNDED_PIC_OPTIONS);
    }

    public static void loadRounedImg(String url, ImageView imgview, DisplayImageOptions options) {
        ImageLoader imageLoader = ImageLoader.getInstance();
        imageLoader.displayImage(url, imgview, options);
    }

    public static void loadBannerImg(String url, ImageView imgview) {
        ImageLoader imageLoader = ImageLoader.getInstance();
        imageLoader.displayImage(url, imgview, BANNER_PIC_OPTIONS);
    }
}
